package cn.initcap.concurrency.concurrency.synccontainer;

import cn.initcap.concurrency.annoations.ThreadSafe;
import cn.initcap.concurrency.concurrency.ThreadPoolCreatHelper;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;

/**
 * 使用Collections的synchoraized的一些方法实现同步容器。
 *
 * @author initcap
 * @date Created in 2018/6/16 PM3:38.
 */
@Slf4j
@ThreadSafe
public class CollectionsExample2 {

    /**
     * 总请求数
     */
    private static final int CLIENT_TOTAL = 5000;

    /**
     * 同时并发执行的线程数
     */
    private static final int THREAD_TOTAL = 200;

    private static Set<Integer> set = Collections.synchronizedSet(Sets.newHashSet());

    public static void update(int i) {
        set.add(i);
    }

    public static void main(String[] args) throws Exception {
        ThreadPoolCreatHelper.threadFinalCountParam(CLIENT_TOTAL, THREAD_TOTAL,
                CollectionsExample2.class, "update",
                "CollectionsExample2");
        log.info("size:{}", set.size());
    }

}
